<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Article_ap extends MY_Controller 
{

    public function __construct()
    {
        parent::__construct();
        $this->load->helper('url');
        $this->load->helper('common');
        $this->load->model('article_model');
    }
    
    /*
    *查看文章
    */
    public function show_article_api()
    {
       $ppage = $this->input->get('ppage');
       $classId = $this->input->get('classId');
       $classInfo = $this->article_model->get_class($classId);//得到分类ID
       $where = $this->article_model->get_article($classInfo['term_id']);//以分类ID找出此分类下的所有文章
       $re = $this->article_model->get_article_list($where,$classInfo['name'], $classId, $ppage);
       if(!$re){
            error_output('暂无文章');
       }
       $resu['status'] = 1;
       $resu['page'] = $re['page'];
       $resu['classdir'] = $re['classdir'];//根类目录名字
       unset($re['page']);  
       unset($re['classdir']);  
       foreach($re as $key=>$val){
           
            $resu['article_list'][$key] = array(
                    'articleTit'=>$val['post_title'],
                    'articleContent'=>mb_substr(strip_tags(preg_replace('/\<img .*? [^>]\>/i', '', $val['post_content'])), 0, 130)."<font size='2'>......</font>",
                    'pubDate'=>$val['post_date'],
                    'author'=>$val['pubadmin'],
                    'img'=>$val['img'],
                    'ID'=>$val['ID'],
                    'classdir'=>$val['classdir'],
             );
       }
         json_output($resu);
    }
    
    /*
    *显示文章详情页
    */
    public function article_content_api()
    {
        $articleID = $this->input->get('articleID');
        $rowarr = $this->article_model->get_article_content($articleID);//取出文章信息
        $comarr = $this->article_model->get_article_comments($articleID);//取出文章的所有评论
        if(!$rowarr){
            error_output('文章内容正在修改中,请等待！！');
        }
        $resu['count'] = $comarr['count'];
        unset($comarr['count']);
        $resu['status'] = 1;
        $resu['comment'] = $comarr;//文章的评论
        preg_match('/<img.+src=\"?(.+\.(jpg|gif|bmp|bnp|png))\"?.+>/i',$rowarr['post_content'],$match);
        $resu['article'] = array(
            'author'=>$rowarr['user_login'],
            'articleContent'=>strip_tags(preg_replace('/<\s*img\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i', '', $rowarr['post_content'])),
            'artileTitle'=>$rowarr['post_title'],
            'date'=>$rowarr['post_date'],
            'img'=>$match[1]
        );
        
        json_output($resu);
    }
    
    /*
    *搜索文章分页
    */
    public function show_search_api()
    {
        $ppage = $this->input->get('ppage');
        $result = $this->article_model->search_page($ppage);
        if(!$result){
            error_output('错误');
        }
        
        $resu['status'] = 1;
        
        
    }
    /*
    *插入评论
    */
    public function insert_comment_api()
    {
        $comment_authorInfo = $_GET['commentInfo'];
        $iden = $this->article_model->insert_comment($comment_authorInfo);
        if(!$iden){
            error_output('评论失败');
        }
        
        $resu['status'] = 1;
        
        $resu['iden'] = $iden;
        
        json_output($resu);
    }
    
     /*
    *插入评论
    */
    public function insert_towcomment_api()
    {
        $towcommentInfo = $_GET['towcommentInfo'];
        $iden = $this->article_model->insert_towcomment($towcommentInfo);
        if(!$iden){
            error_output('评论失败');
        }
        
        $resu['status'] = 1;
        $resu['towiden'] = $iden;
        json_output($resu);
    }
    
     /*
    *del评论
    */
    
    public function del_towcomment_api()
    {
        $delID = $this->input->get('delID');
        $iden = $this->article_model->del_t_comment($delID);
        if(!$iden){
            error_output('删除评论失败');
        }
        
        $resu['status'] = 1;
        $resu['iden'] = $iden;
        json_output($resu);
    }
    
     /*
    *del评论
    */
    public function del_parentcomment_api()
    {
        $delID = $this->input->get('delID');
        $iden = $this->article_model->del_p_comment($delID);
        if(!$iden){
            error_output('删除评论失败');
        }
        
        $resu['status'] = 1;
        $resu['iden'] = $iden;
        json_output($resu);
    }
/*
	
    /*
    *获取产品列表

    public function get_ao_product_api()
    {
         $proarr = $this->welcome_model->get_pro(); 
         
        if(!$proarr)
        {
            error_output('当前没有产品');
        }
        $resu['status'] = 1;

        foreach ($proarr as $key => $val) {
            $resu['pro_List'][$key] = array(
				'proId' => $val['id'],  //产品ID
				'proName' => $val['proname'], //产品名称
				'proDesc' => $val['prodesc'],   //产品描述
				'proImg' => $val['proimg'],   //产品图片
				'effect' => $val['effect'],   //产品图片
        	);
        }
       json_output($resu);
         
    }
    
    /*
    *获取单个产品的内容

    public function get_pro_content_api()
    {
        $id= $this->input->get('id');
        $proInfo = $this->welcome_model->get_pro_content($id);
        $proOtherInfo = $this->welcome_model->get_otherpro_content($id);
        $proInfo['other'] = $proOtherInfo;
        if(!$proInfo){
            error_output('产品信息有误');
        }
        json_output($proInfo);
    }
 
     /*
    *获取（关于他们）列表信息
   
    public function get_withOther_api()
    {
        if(isset($_GET['type'])){
           $type = $_GET['type'];
        }else{
           $type=false;
        }
        $withOther = $this->welcome_model->get_with_list($type);
        if(!$withOther){
            error_output('无关于他们图片信息');
        }
        $resu['status'] = 1;
        
        foreach($withOther as $k=>$v){
            $resu['with_list'][$k]  = array(
                'withId' => $v['id'],
                'withName' => $v['name'],
                'withImg' => $v['img'],
                'withDesc' => $v['descri'],
            );
        }
         json_output($resu);
    }
    
    public function get_rowOther_api()
    {
        $id = $this->input->get('id');
        $rowArr = $this->welcome_model->get_rowOther($id);
        if(!$rowArr){
            error_output('用户信息有误');
        }
        $resu['status'] = 1;
        $resu['row_arr'] = $rowArr;
        json_output($resu);
    }
   */ 
    
 }
